<template>
    <div style="padding: 30px">
        <div>职位审核信息</div>
        <div style="margin-top: 20px">
            <el-menu :default-active="activeIndex"
                     class="el-menu-demo"
                     mode="horizontal"
                     @select="handleSelect">
                <el-menu-item index="1" @click="ispass = 1">审核通过</el-menu-item>
                <el-menu-item index="2" @click="ispass = 0">审核未通过</el-menu-item>
            </el-menu>
        </div>
        <!--职位详情信息容器-->
        <div class="position_manager_info_contain">
            <!--数据内容-->
            <div>
                <el-table
                        ref="multipleTable"
                        :data="tableData"
                        tooltip-effect="dark"
                        style="width: 100%"
                        @selection-change="handleSelectionChange">
                    <el-table-column
                            type="selection"
                            width="55">
                    </el-table-column>

                    <el-table-column
                            label="职位名称"
                            width="180"
                            prop="jobName">
                    </el-table-column>

                    <el-table-column
                            prop="jobDeptement"
                            label="职位部门"
                            width="180">
                    </el-table-column>

                    <el-table-column
                            prop="isUrgency"
                            label="急聘"
                            width="150">
                        <template slot-scope="scope">
                            <el-tag
                                :type="scope.row.isUrgency == 1?'danger':'success'"
                            >
                                  <span  v-if="scope.row.isUrgency == 1">
                                      急
                                  </span>

                                <span v-else>
                                    正常
                                </span>
                            </el-tag>
                        </template>
                    </el-table-column>

                    <el-table-column
                            prop="jobRecruitStatus"
                            label="招聘状态"
                            width="150">
                        <template slot-scope="scope">
                            <el-tag type="success" v-if="scope.row.jobRecruitStatus == '10310'">
                                <span>正在招聘</span>
                            </el-tag>

                            <el-tag type="warning" v-else-if="scope.row.jobRecruitStatus == '10320'">
                                <span>暂停招聘</span>
                            </el-tag>

                            <el-tag type="danger" v-else-if="scope.row.jobRecruitStatus == '10330'">
                                <span>停止招聘</span>
                            </el-tag>
                        </template>

                    </el-table-column>

                    <el-table-column
                            prop="createTime"
                            label="创建时间"
                            width="180">
                    </el-table-column>

                    <el-table-column
                            fixed="right"
                            label="操作"
                            width="200"
                            >
                        <template slot-scope="scope">
                            <el-button
                                type="text"
                                size="small"
                                @click="pauseRecruit(scope.row)"
                            >
                            暂停招聘
                            </el-button>

                            <el-button
                                type="text"
                                size="small"
                                @click="stopRecruit(scope.row)"
                            >
                            停止招聘
                            </el-button>

                            <el-button
                                type="text"
                                size="small"
                                @click="continueRecruit(scope.row)"
                            >
                                继续招聘
                            </el-button>
<!--                            <el-button
                                    @click.native.prevent="deleteRow(scope.$index, tableData)"
                                    type="text"
                                    size="small">
                                移除
                            </el-button>-->
                        </template>
                    </el-table-column>
                </el-table>
            </div>

            <!--分页条-->
            <div style="text-align: center;margin-top: 15px">
                <div class="block">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="currentPage"
                            :page-sizes="pageSizes"
                            :page-size="pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
    import user from "@/api/user";
    import workjobApi from "@/api/workjobs/workjobApi";

    export default {
        inject:['reload'],
        name: "my-publish-workjob-info",
        data(){
            return{
                activeIndex:'1' ,        //默认选中的菜单
                ispass:1,               //这个字段是用来负责职位的审核有没有通过的
                tableData: [],
                multipleSelection: [],  //多选框


                currentPage:1,          //分页设置
                pageSizes:[1,2,3,4],    //每一页显示的条目数
                total:0,                //总条数
                pageSize:3,             //总页数量
                approveStatus: '10110',      //10120 未审核 //10110 已审核
                userId:'',

            }
        },
        mounted() {
            this.isPass()
            this.loadinit()
        },
        methods:{
            pauseRecruit(obj){
                console.log("obj pause ==>",obj)
                workjobApi.pauseRecruit(obj.id)
                .then(data => {
                    console.log("workjobApi ===>> ",workjobApi)
                    if (data.data.code === 0){
                        this.$message({
                            type:'success',
                            message:data.data.msg
                        })
                        //刷新页面
                        this.reload()
                    }else{
                        this.$message({
                            type:'warning',
                            message:data.data.msg
                        })
                    }
                })
                .catch(err => {
                    Promise.reject(err)
                })
            },

            stopRecruit(obj){
                console.log("stop obj ==>",obj)
                workjobApi.stopRecruit(obj.id)
                    .then(data => {
                        if (data.data.code === 0){
                            this.$message({
                                type:'success',
                                message:data.data.msg
                            })
                            //刷新页面
                            this.reload()
                        }else{
                            this.$message({
                                type:'warning',
                                message:data.data.msg
                            })
                        }
                    })
                    .catch(err => {
                        Promise.reject(err)
                    })
            },

            continueRecruit(obj){
                console.log("obj continueRecruit ==>" , obj)
                workjobApi.continueRecruit(obj.id)
                .then(data=>{
                    if (data.data.code === 0){
                        this.$message({
                            type:'success',
                            message:data.data.msg
                        })
                        //刷新页面
                        this.reload()
                    }else{
                        this.$message({
                            type:'warning',
                            message:data.data.msg
                        })
                    }
                })
                .catch(err=>{
                    Promise.reject(err)
                })
            },


            /*加载信息*/
            loadinit(){
                const userId = JSON.parse(localStorage.getItem("user")).userId
                this.userId = userId

                workjobApi.loadinit(this.currentPage,this.pageSize,this.userId,this.approveStatus,this.ispass)
                .then(data => {
                    if (data.data.code === 0){
                        this.tableData = data.data.page.list                //
                        this.currentPage = data.data.page.currPage          //当前页码
                        this.pageSize = data.data.page.pageSize             //当前每页的条数数量
                        this.total = data.data.page.totalCount              //总页数
                    }
                })
                .catch(error => {
                    Promise.reject(error)
                })
            },

            isPass(){
                if (this.ispass === 1){
                    this.ispass = 1
                    //this.approveStatus = '10110'
                    this.loadinit()
                }else{
                    this.ispass = 0
                    //this.approveStatus = '10120'
                    this.loadinit()
                }
            },
            handleSelect(){

            },

            //多选框信息
            handleSelectionChange(){

            },

            //当选择每一页的size数量改变时候触发
            handleSizeChange(value){
                //console.log("SizeChange:",value)
                this.pageSize = value
                this.loadinit()
            },
            handleCurrentChange(value){
                //console.log("currentPage:",value)
                this.currentPage = value
                this.loadinit()
            },
        },
        //计算属性
        computed:{
            getIspass(){
                return this.ispass
            }
        },
        //监听属性，用来监听ispass属性值的变化
        watch:{
            getIspass:{
                handler(){
                    this.isPass()
                }
            }
        }
    }
</script>

<style>

</style>
